package com.vehicle_information_management_system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vehicle_information_management_system.mapper.DriverInfoMapper;
import com.vehicle_information_management_system.pojo.DrivingCostInfo;
import com.vehicle_information_management_system.service.DrivingCostInfoService;
import com.vehicle_information_management_system.mapper.DrivingCostInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
* @author huawei
* @description 针对表【driving_cost_info】的数据库操作Service实现
* @createDate 2025-02-17 10:08:19
*/
@Service
public class DrivingCostInfoServiceImpl extends ServiceImpl<DrivingCostInfoMapper, DrivingCostInfo>
    implements DrivingCostInfoService{

    @Autowired
    private DrivingCostInfoMapper drivingCostInfoMapper;
    @Override
    public IPage<DrivingCostInfo> getDrivingCostInfo(Integer pageNum, Integer pageSize, String search) {
        Page<DrivingCostInfo> page = new Page<>(pageNum,pageSize);
        QueryWrapper<DrivingCostInfo> queryWrapper = new QueryWrapper<>();
        if(StrUtil.isNotBlank(search)){
            queryWrapper.like("cost",search).or().like("cost_type",search)
                    .or().like("t.usage_time",search);
        }
        return drivingCostInfoMapper.getDrivingCostInfo(page,queryWrapper);
    }

    @Override
    public void add(DrivingCostInfo drivingCostInfo) {
         drivingCostInfoMapper.insert(drivingCostInfo);
    }

    @Override
    public void delete(Integer id) {
        drivingCostInfoMapper.deleteById(id);
    }

    @Override
    public void update(DrivingCostInfo drivingCostInfo) {
        drivingCostInfoMapper.updateDrivingCostInfo(drivingCostInfo);
    }

    @Override
    public Double getDrivingCostInfoByMonth() {
        return drivingCostInfoMapper.getMonthlyCostSum();
    }

    @Override
    public List<DrivingCostInfo> getDrivingCostInfoByUserId(Integer userId) {
        return drivingCostInfoMapper.selectList(new QueryWrapper<DrivingCostInfo>().eq("user_id",userId));
    }
}




